class Solution:
    def maximumCostSubstring(self, s: str, chars: str, vals: List[int]) -> int:
        cost = [0]*26
        for i in range(26):
            cost[i] = i + 1
        for i in range(len(chars)):
            cost[ord(chars[i]) -ord('a')] = vals[i]
        dp = [0] * 100010
        ans = 0
        for i in range(1,len(s) + 1):
            # === py 字符转ascii码
            index = ord(s[i - 1]) - ord('a')
            dp[i] = max(cost[index] , dp[i - 1] + cost[index])
            ans = max(ans,dp[i])
        return ans